//
//  RWRemindHeadView.m
//  Chat
//
//  Created by 任伟 on 16/3/7.
//  Copyright © 2016年 任伟. All rights reserved.
//

#import "RWRemindHeadView.h"
#import "RWRemindListView.h"

@interface RWRemindHeadView()

@property (nonatomic, strong) UIImageView *directionImage;
@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UIView *ringView1;
@property (nonatomic, strong) UIView *ringView2;
@property (nonatomic, strong) UIView *ringView3;
@property (nonatomic, strong) RWRemindListView *listView;

@end

@implementation RWRemindHeadView

- (void)initSubView {
    self.listView = [[RWRemindListView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.width)];
    self.listView.transform = CGAffineTransformMakeScale(0.01f, 0.01f);
    self.listView.transform = CGAffineTransformRotate (self.listView.transform, -M_PI_2);
    [self addSubview:self.listView];
    self.listView.centerX = self.width/2;
    self.listView.centerY = self.height/2 - 64;
    
    //外边框
    self.ringView1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width/5.5, self.width/5.5)];
    [self.ringView1 setBackgroundColor:RGBACOLOR(220.0, 220.0, 240.0, 1.0)];
    [self.ringView1.layer setCornerRadius:self.ringView1.width/2];
    self.ringView1.center = self.listView.center;
    [self addSubview:self.ringView1];
    
    self.ringView2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width/5.5, self.width/5.5)];
    [self.ringView2 setBackgroundColor:RGBACOLOR(225.0, 212.0, 243.0, 1.0)];
    [self.ringView2.layer setCornerRadius:self.ringView2.width/2];
    self.ringView2.center = self.listView.center;
    [self addSubview:self.ringView2];
    
    self.ringView3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.width/5.5, self.width/5.5)];
    [self.ringView3 setBackgroundColor:RGBACOLOR(236.0, 189.0, 156.0, 1.0)];
    [self.ringView3.layer setCornerRadius:self.ringView3.width/2];
    self.ringView3.center = self.listView.center;
    [self addSubview:self.ringView3];
    
    
    self.bulbImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.width/5, self.width/4)];
    [self.bulbImage setImage:[UIImage imageNamed:@"BulbImage"]];
    [self addSubview:self.bulbImage];
    self.bulbImage.center = self.listView.center;
    
    self.directionImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 19, 6)];
    [self.directionImage setImage:[UIImage imageNamed:@"up_reminder"]];
    [self addSubview:self.directionImage];
    
    self.listView.centerY = self.height/2;
    self.backView.centerY = self.listView.centerY;
    self.ringView1.centerY = self.listView.centerY;
    self.ringView2.centerY = self.listView.centerY;
    self.ringView3.centerY = self.listView.centerY;
    self.bulbImage.centerY = self.listView.centerY+10;
    self.directionImage.centerX = self.width/2;
    self.directionImage.top = self.height - 20;
}

- (void)beginAnimationg  //放大
{
    //闪烁动画
    self.userInteractionEnabled = NO;
    self.bulbImage.userInteractionEnabled = NO;
    [self.listView hideTitle];
    self.ringView1.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
    [UIView animateWithDuration:0.45f animations:^{
        self.ringView1.transform=CGAffineTransformMakeScale(1.8f, 1.8f);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.45f animations:^{
            self.ringView1.transform = CGAffineTransformMakeScale(1.7f, 1.7f);
        } completion:^(BOOL finished) {
        }];
    }];
    
    self.ringView2.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
    [UIView animateWithDuration:0.3f animations:^{
        self.ringView2.transform=CGAffineTransformMakeScale(1.6f, 1.6f);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3f animations:^{
            self.ringView2.transform = CGAffineTransformMakeScale(1.5f, 1.5f);
        }];
    }];
    
    self.ringView3.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
    [UIView animateWithDuration:0.15f animations:^{
        self.ringView3.transform=CGAffineTransformMakeScale(1.4f, 1.4f);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.15f animations:^{
            self.ringView3.transform = CGAffineTransformMakeScale(1.3f, 1.3f);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                             animations:^(void) {
                                 self.listView.transform =  CGAffineTransformMakeScale(1.0f, 1.0f);
                                 self.listView.transform = CGAffineTransformRotate (self.listView.transform, 0);
                             }completion:^(BOOL finished) {
                                 self.userInteractionEnabled = YES;
                                 [self.listView showTitle];
                             }];
        }];
    }];
}

- (void)endAnimationg
{
    self.bulbImage.userInteractionEnabled = YES;
    //旋转动画
    [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
                     animations:^(void) {
                         self.listView.transform = CGAffineTransformMakeScale(0.01f, 0.01f);
                         self.listView.transform = CGAffineTransformRotate (self.listView.transform, -M_PI_2);
                     }completion:nil];
    
    //闪烁
    [UIView animateWithDuration:0.45f animations:^{
        self.ringView1.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
    }];
    [UIView animateWithDuration:0.30f animations:^{
        self.ringView2.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
    }];
    [UIView animateWithDuration:0.15f animations:^{
        self.ringView3.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
    }];
}


// 合上
- (void)packUpView {
    
    [self endAnimationg];
    [UIView animateWithDuration:0.5 animations:^{
        self.listView.centerY = self.height/2;
        self.backView.centerY = self.listView.centerY;
        self.ringView1.centerY = self.listView.centerY;
        self.ringView2.centerY = self.listView.centerY;
        self.ringView3.centerY = self.listView.centerY;
        self.bulbImage.centerY = self.listView.centerY+10;
        self.directionImage.top = self.height - 20;
    } completion:^(BOOL finished) {
        [self.directionImage setImage:[UIImage imageNamed:@"down_reminder"]];
    }];
}

// 展开
- (void)openView {
    
    [self beginAnimationg];
    [UIView animateWithDuration:0.5 animations:^{
        self.listView.centerY = self.height/2;
        self.backView.centerY = self.listView.centerY;
        self.ringView1.centerY = self.listView.centerY;
        self.ringView2.centerY = self.listView.centerY;
        self.ringView3.centerY = self.listView.centerY;
        self.bulbImage.centerY = self.listView.centerY+10;
        self.directionImage.top = self.height - 20;
    } completion:^(BOOL finished) {
        [self.directionImage setImage:[UIImage imageNamed:@"up_reminder"]];
    }];
}

@end
